package com.example.administrator.mynews.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.mynews.R;
import com.example.administrator.mynews.bean.GuoKeListBean;

import java.util.List;

/**
 * Created by Administrator on 2017/5/16.
 */

public class GuoKeRecyclerViewAdapter extends RecyclerView.Adapter<GuoKeRecyclerViewAdapter.MyGuoKeHolder> {
    private LayoutInflater inflater;
    private Context mConetxt;
    private List<GuoKeListBean.ResultBean> resultBeanList;

    public GuoKeRecyclerViewAdapter(Context context, List<GuoKeListBean.ResultBean> resultBeanList) {
        this.mConetxt = context;
        this.resultBeanList = resultBeanList;
        inflater= LayoutInflater.from(context);
    }

    @Override
    public MyGuoKeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.item_guoke,parent,false);
        MyGuoKeHolder myGuoKeHolder=new MyGuoKeHolder(view);
        return myGuoKeHolder;
    }

    @Override
    public void onBindViewHolder(MyGuoKeHolder holder, int position) {
        holder.tvTitle.setText(resultBeanList.get(position).getTitle());
        holder.tvTime.setText(resultBeanList.get(position).getDate_created());
        holder.tvContent.setText(resultBeanList.get(position).getSummary());
        Glide.with(mConetxt)
                .load(resultBeanList.get(position).getSmall_image())
                .into(holder.imgIcon);
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return resultBeanList.size();
    }

    class MyGuoKeHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        ImageView imgIcon;
        TextView tvTitle;
        TextView tvTime;
        TextView tvContent;
        ImageView imgHide;
        public MyGuoKeHolder(View itemView) {
            super(itemView);
            imgIcon= (ImageView) itemView.findViewById(R.id.img_item_guoke_icon);
            imgHide= (ImageView) itemView.findViewById(R.id.img_item_guoke_hide_btn);
            tvTitle= (TextView) itemView.findViewById(R.id.tv_item_guolke_title);
            tvTime= (TextView) itemView.findViewById(R.id.tv_item_guolke_time);
            tvContent= (TextView) itemView.findViewById(R.id.tv_item_guolke_content);

            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            onGuoKeClickItemListener.onClickItem((Integer) v.getTag());
        }


    }
    OnGuoKeClickItemListener onGuoKeClickItemListener;

    public void setOnGuoKeClickItemListener(OnGuoKeClickItemListener onGuoKeClickItemListener){
        this.onGuoKeClickItemListener=onGuoKeClickItemListener;
    }

    public interface OnGuoKeClickItemListener{
        void onClickItem(int pos);
    }
}
